package com.resume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.resume.bean.PageBean;
import com.resume.domain.User;
import com.resume.domain.UserQuery;
import com.resume.mapper.UserMapper;
import com.resume.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @Author: 梁云亮
 * @Date: 2021/7/14 13:51
 * @Describe:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public PageBean<User> pageUser(UserQuery userQuery) {
        IPage<User> page = new Page<>(userQuery.getPageNum(),userQuery.getPageSize());

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();

        if (userQuery.getId() != null) {
            queryWrapper.eq("id", userQuery.getId());
        }
        if (userQuery.getName() != null) {
            queryWrapper.like("name", userQuery.getName());
        }
        if (userQuery.getNickname() != null) {
            queryWrapper.like("nickname", userQuery.getNickname());
        }
        if (userQuery.getAccount() != null) {
            queryWrapper.eq("account", userQuery.getAccount());
        }
        if (userQuery.getGender() != null) {
            queryWrapper.eq("gender", userQuery.getGender());
        }
        if (userQuery.getBirth1() != null) {
            queryWrapper.ge("birth", userQuery.getBirth1());
        }
        if (userQuery.getBirth2() != null) {
            queryWrapper.le("birth", userQuery.getBirth2());
        }
        if (userQuery.getTel() != null) {
            queryWrapper.eq("tel", userQuery.getTel());
        }
        if (userQuery.getEmail() != null) {
            queryWrapper.eq("email", userQuery.getEmail());
        }
        if (userQuery.getQq() != null) {
            queryWrapper.eq("qq", userQuery.getQq());
        }
        if (userQuery.getWechat() != null) {
            queryWrapper.eq("wechat", userQuery.getWechat());
        }
        if (userQuery.getHomePage() != null) {
            queryWrapper.eq("home_page", userQuery.getHomePage());
        }
        if (userQuery.getHuJiId() != null) {
            queryWrapper.eq("hu_ji_id", userQuery.getHuJiId());
        }
        if (userQuery.getJuZhuId() != null) {
            queryWrapper.eq("ju_zhu_id", userQuery.getJuZhuId());
        }
        if (userQuery.getStatus() != null) {
            queryWrapper.eq("status", userQuery.getStatus());
        }
        if (userQuery.getCreateTime1() != null) {
            queryWrapper.ge("create_time", userQuery.getCreateTime1());
        }
        if (userQuery.getCreateTime2() != null) {
            queryWrapper.le("create_time", userQuery.getCreateTime2());
        }
        if (userQuery.getRoleId() != null) {
            queryWrapper.eq("role_id", userQuery.getRoleId());
        }

        baseMapper.selectPage(page, queryWrapper);
        PageBean<User> pageBean = PageBean.init(page);

        return pageBean;
    }


}
